import api from '@/api';

export default {
  namespace: 'infoaccount',

  state: {
    accountInfo: {},
    isEdit: false
  },

  effects: {
    *fetchInfo({ payload }, { call, put }) {
      const response = yield call(api.info.queryAccountInfo, payload);   
      console.log('res...',response)
      if (response.code === 200) {
        yield put({
          type: 'save',
          payload: response
        });
      }
    },
    *modfiyInfo({payload}, { call, put }) {
      return yield call(api.info.modifyInfo, payload)
    },
    *sendMes({payload}, { call, put}) {
      return yield call(api.info.sendMes, payload)
      
    },
    *validateCode({payload}, {call, put}) {      
      return yield call(api.info.validateCode, payload)
    },
    *modifyMobile({payload}, { call, put}) {
      return yield call(api.info.modifyMobile, payload)
    }
  },

  reducers: {
    save(state, action) {
      const { data } = action.payload
      return {
        ...state,
        accountInfo: data
      };
    },
    toggleEdit(state, action){
      return {
        ...state,
        isEdit: !state.isEdit
      }
    }
  }
};
